<?php

/**
 * Main application entry point
 *
 */
class Default_Controller extends SPF_Controller {

   /**
    * The version number of the controller.
    * @var     string
    */
   const VERSION = '1.0.0';

   /**
    * The author of the controller.
    * @var     string
    */
   const AUTHOR  = 'Simon Downes';

   /**
    * Constructor
    * @access       public
    * @return       void
    */
   public function __construct() {
      /* construct the parent object */
      parent::__construct(__CLASS__);
   }

   /**
    * Destructor
    * @access       public
    * @return       void
    */
   public function __destruct() {
      parent::__destruct();
   }

   /**
    * Determines if the current user is permitted to access this controller and perform the requested action
    * @return       boolean   true if access is allowed, false otherwise.
    */
   public function authenticate() {
   
      return (SPF::$session->user != NULL);
      
   } // authenticate
   
   /**
    * This method is run by the controller if an action is not specified in the user's request
    * @access       public
    */
   public function index( $filter = NULL ) {
      
      switch( $filter ) {
         
         case 'assigned_me':
         case 'created_me':
         case 'created_today':
         case 'updated_today':
            break;
            
         default:
            $filter = 'assigned_me';
            break;
            
      } // switch
      
      $this->assign('filter', $filter);
      $this->assign('tickets', Ticket::dashboard_data($filter));
      $this->assign('projects', Project::browse_data());
      
      $this->display('index');
      
   } // index
   
   public function admin() {
      
      $this->assign('project_count', SPF::$db->get_count('projects'));
      
      $this->assign('ticket_count', SPF::$db->get_count('tickets'));
      $this->assign('ticket_data', Ticket::get_count_by_status(true));
      
      $this->assign('user_count', SPF::$db->get_count('users'));
      $this->assign('user_data', User::get_count_by_status());
            
      $this->display('admin');
      
   
   } // admin
   
} // Default_Controller

?>
